package cn.edu.pzhu.javaweb.service.imp;

import java.util.ArrayList;
import java.util.List;
import cn.edu.pzhu.javaweb.dao.FileMsgDao;
import cn.edu.pzhu.javaweb.dao.imp.FileMsgDaoimp;
import cn.edu.pzhu.javaweb.pojo.FileMsg;
import cn.edu.pzhu.javaweb.pojo.Result;
import cn.edu.pzhu.javaweb.service.FileService;

public class FileServiceImp implements FileService {
	private FileMsgDao fileMsgDao = new FileMsgDaoimp();

    @Override
    public Result<List<FileMsg>> showFilesList() {
        return Result.success(fileMsgDao.selectAll());
    }

    @Override
    public Result<String> deleteFile(Integer FileInt) {
        // TODO Auto-generated method stub
        return null;
    }

	@Override
	public Result<List<FileMsg>> showFileByPages(int page, int num, int totalpage) {
		// 当没有文件时，直接返回空列表
		if(totalpage <= 0) {
		    return Result.success(new ArrayList<>());
		}
		
		if(page<1) {
		    page = 1;
		}
		if(page > totalpage) {
		    page = totalpage;
		}
		if(num<1) {
		    num = 10;
		}
		int start = (page-1)*num;
		return Result.success(fileMsgDao.selectByRange(start, num));
	}
}